<?php
class Quantity_model extends General_db_model
{
	private $tbl_quantity = 'tbl_publication_quantity';
	function total_quantity()
	{
                $this->db->where('type', 'en');
                $total = $this->db->count_all_results($this->tbl_quantity);
		//$total_en_np = $this->countTotal($this->tbl_quantity);
                //$total = $total_en_np;
                return $total;
	}

	function get_quantity($limit=NULL, $start=NULL)
	{
		//$this->db->select('*');
                $query = "select tpq.*, tpi.title as publication_title, tpi.image as publication_image, tpi.coding as publication_coding, tpi.abstract as publication_excerpt from tbl_publication_quantity as tpq
                            join tbl_publication_info as tpi
                            on tpi.id = tpq.publication_id
                            where type=? limit ?, ? ";
                $result_en = $this->db->query($query, array('en',(int)$start,(int)$limit));
                $result_np = $this->db->query($query, array('np',(int)$start, (int)$limit));
		//$query_en = $this->db->get_where($this->tbl_quantity, array('type'=>'en'), $limit, $start);
                //$query_np = $this->db->get_where($this->tbl_quantity, array('type'=>'np'), $limit, $start);
                $finalResult = array(
                    'en'=>$result_en->result(),
                    'np'=>$result_np->result()
                );
                return $finalResult;
                //debug_array($finalResult);exit;
	}
        function get_quantity_by_pub_type($publication_id, $type,$select='*'){
                $this->db->select($select);
		$this->db->where('publication_id', $publication_id);
		$this->db->where('type', $type);
		$query = $this->db->get($this->tbl_quantity);
		$result = $query->row();
		if($select == '*')
			return $result;
		else
		{
			return $result->$select;
		}
        }
}
?>